
package org.springblade.modules.auth.endpoint;

import com.alibaba.fastjson.JSON;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.wf.captcha.SpecCaptcha;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.common.cache.CacheNames;
import org.springblade.core.cache.constant.CacheConstant;
import org.springblade.core.cache.utils.CacheUtil;
import org.springblade.core.jwt.JwtUtil;
import org.springblade.core.jwt.props.JwtProperties;
import org.springblade.core.launch.constant.AppConstant;
import org.springblade.core.launch.constant.TokenConstant;
import org.springblade.core.log.annotation.ApiLog;
import org.springblade.core.redis.cache.BladeRedis;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.WebUtil;
import org.springblade.modules.auth.provider.ITokenGranter;
import org.springblade.modules.auth.provider.TokenGranterBuilder;
import org.springblade.modules.auth.provider.TokenParameter;
import org.springblade.modules.auth.utils.TokenUtil;
import org.springblade.modules.system.entity.UserInfo;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.time.Duration;
import java.util.UUID;

/**
 * 令牌端点
 *
 * @author Chill
 */
@Slf4j
@Api(value = "用户授权认证", tags = "授权接口")
@RequestMapping("/bladenotify")
@RestController
public class NotifyNoTokenPoint {

	@PostMapping("/unauth/noty")
	@ApiOperation(value = "内网穿透回调测试")
	public R noty(HttpServletRequest request) {
		try {
			request.setCharacterEncoding("utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		log.error("\n\t===回调===toJSONString==============="+ JSON.toJSONString(request));
		BufferedReader reader;
		String responseStr = "";
		try {
			reader = request.getReader();
			String line;
			StringBuffer inputString = new StringBuffer();
			while ((line = reader.readLine()) != null) {
				inputString.append(line);
			}
			responseStr = inputString.toString();
			log.error("\n\t===回调===responseStr==============="+ responseStr);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return R.success("操作成功");
	}

//	@GetMapping("/unauth/noty")
//	@ApiOperation(value = "内网穿透回调测试")
//	public R noty(HttpServletRequest request) {
//		BufferedReader reader;
//		String responseStr = "";
//		try {
//			reader = request.getReader();
//			String line;
//			StringBuffer inputString = new StringBuffer();
//			while ((line = reader.readLine()) != null) {
//				inputString.append(line);
//			}
//			responseStr = inputString.toString();
//			log.error("\n\t===回调===responseStr==============="+ responseStr);
//		} catch (IOException e) {
//			e.printStackTrace();
//		}
//		return R.success("操作成功");
//	}

	@GetMapping("/unauth/wbcxnotify")
	@ApiOperation(value = "回调", notes = "回调")
	public R wbcxnotify(HttpServletRequest request) {
		log.error("\n\t===回调=request所有==toJSONString=============="+ JSON.toJSONString(request));
		BufferedReader reader;
		String responseStr = "";
		try {
			reader = request.getReader();
			String line;
			StringBuffer inputString = new StringBuffer();
			while ((line = reader.readLine()) != null) {
				inputString.append(line);
			}
			responseStr = inputString.toString();
			log.error("\n\t===回调===responseStr==============="+ responseStr);
		} catch (IOException e) {
			e.printStackTrace();
		}

		return R.success("操作成功");
	}


}
